package com.feng.system.service.impl;

import com.feng.common.SystemConstants;
import com.feng.common.utils.StringUtils;
import com.feng.system.domain.SysDept;
import com.feng.system.mapper.SysDeptMapper;
import com.feng.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部门管理 服务实现
 *
 * @author RoyWang
 */
@Service
public class SysDeptServiceImpl implements ISysDeptService {

    @Autowired
    private SysDeptMapper deptMapper;

    @Override
    public List<SysDept> selectDeptList(SysDept dept) {
        return deptMapper.selectDeptList(dept);
    }

    @Override
    public String checkDeptNameUnique(SysDept dept) {
        int deptId = StringUtils.isNull(dept.getDeptId()) ? 0 : dept.getDeptId();
        SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
        if (StringUtils.isNotNull(info) && info.getDeptId() != deptId) {
            return SystemConstants.NOT_UNIQUE;
        }
        return SystemConstants.UNIQUE;
    }

    @Override
    public int insertDept(SysDept dept) {
        return deptMapper.insertDept(dept);
    }

    @Override
    public int updateDept(SysDept dept) {
        return deptMapper.updateDept(dept);
    }

    @Override
    public int deleteDeptById(int deptId) {
        return deptMapper.deleteDeptById(deptId);
    }

    @Override
    public SysDept selectDeptById(int deptId) {
        return deptMapper.selectDeptById(deptId);
    }
}
